package cn.seaboot.excel;

import cn.seaboot.commons.file.IOUtils;
import cn.seaboot.excel.sax.ExcelContext;
import cn.seaboot.excel.sax.TableParser;
import cn.seaboot.excel.sax.XmlToExcel;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.dom4j.DocumentException;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author Mr.css
 * @version 2025-06-30 17:20
 */
public class HtmlToExcel {

    public static void main(String[] args) throws IOException, DocumentException {
        String file = "D:\\seaboot\\seaboot\\commons-office\\src\\test\\resources\\table.html";

        try (Workbook workbook = new XSSFWorkbook()) {
            Sheet sheet = workbook.createSheet();

            ExcelContext context = new ExcelContext();
            context.setSheet(sheet);

            TableParser parser = new TableParser();
            parser.setContext(context);

            try (InputStream is = IOUtils.openFileInputStream(file)) {
                parser.parse(is);
            }

            try (OutputStream os = IOUtils.openFileOutputStream("C:\\Users\\postm\\Desktop\\ret.xlsx")) {
                workbook.write(os);
            }
        }
    }
}
